{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "生成一段程序，列出zy7文件夹下241021.xls所有文件内容相同的文件名\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The file 241021.xls does not exist in the folder zy7.\n",
      "No files with the same content as 241021.xls found.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "def read_file_content(file_path):\n",
    "    with open(file_path, 'rb') as file:\n",
    "        return file.read()\n",
    "\n",
    "def find_duplicate_files(target_folder, target_file):\n",
    "    target_file_path = os.path.join(target_folder, target_file)\n",
    "    if not os.path.isfile(target_file_path):\n",
    "        print(f\"The file {target_file} does not exist in the folder {target_folder}.\")\n",
    "        return []\n",
    "\n",
    "    target_content = read_file_content(target_file_path)\n",
    "    duplicate_files = []\n",
    "\n",
    "    for root, dirs, files in os.walk(target_folder):\n",
    "        for file in files:\n",
    "            file_path = os.path.join(root, file)\n",
    "            if file_path != target_file_path and os.path.isfile(file_path):\n",
    "                if read_file_content(file_path) == target_content:\n",
    "                    duplicate_files.append(file)\n",
    "\n",
    "    return duplicate_files\n",
    "\n",
    "def main():\n",
    "    target_folder = 'zy7'\n",
    "    target_file = '241021.xls'\n",
    "    duplicates = find_duplicate_files(target_folder, target_file)\n",
    "    if duplicates:\n",
    "        print(f\"Files with the same content as {target_file}:\")\n",
    "        for duplicate in duplicates:\n",
    "            print(duplicate)\n",
    "    else:\n",
    "        print(f\"No files with the same content as {target_file} found.\")\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
